<template>
  <div class="company-info">
    <div v-show="addCompanyFlag==0">
      <h3>企业信息</h3>
      <div style="text-align:right;">
        <button class="addBtn cursor-point" @click="addCompanyInfo">添加企业信息</button>
      </div>
      <Table :columns="classifyGroup" :data="companyInfoGroup"></Table>
      <div style="margin: 10px;overflow: hidden">
        <div style="float: right;">
          <!-- <Page :total="companyInfoGroup.length" :current="1" @on-change="changePage" show-elevator prev-text="上一页" next-text="下一页"></Page> -->
        </div>
      </div>
      <Modal
        class="edit-company-info"
        v-model="isShowEditInfo"
        ok-text="保存"
        cancel-text="关闭"
        class-name="vertical-center-modal"
        @onOk="emitEntInfo"
      >
        <h3>添加营业执照</h3>
        <div class="edit-company-info-content">
          <Form :model="formItem" :label-width="160">
            <FormItem label="企业名称">
              <Input v-model="formItem.entName" placeholder="请输入企业名称"/>
              <!-- <p>国网金融科技集团</p> -->
            </FormItem>
            <FormItem label="统一社会信用代码">
              <Input v-model="formItem.creditCode" placeholder="请输入统一社会信用代码"/>
              <!-- <p>123467887654321</p> -->
            </FormItem>
            <FormItem label="法定代表人">
              <Input v-model="formItem.legalPerson" placeholder="请输入法定代表人"/>
              <!-- <p>张伟</p> -->
            </FormItem>
            <FormItem label="法定代表人身份证号">
              <Input v-model="formItem.legalRepreIden" placeholder="请输入法人身份证号" />
            </FormItem>
            <FormItem label="法定代表人手机号">
              <Input v-model="formItem.legalReprePhone" placeholder="请输入法人手机号" />
            </FormItem>
            <FormItem label="注册资本(万)">
              <Input v-model="formItem.registCost" placeholder="请输入注册资本"/>
              <!-- <p>200,000</p> -->
            </FormItem>
            <FormItem label="联系人">
              <Input v-model="formItem.creditCode" placeholder="张伟" />
            </FormItem>
            <FormItem label="Radio">
              <RadioGroup v-model="formItem.radio">
                <Radio label="man">先生</Radio>
                <Radio label="woman">女士</Radio>
              </RadioGroup>
            </FormItem>
            <FormItem label="企业地址" prop="addressArrEnt">
              <Cascader :data="JSON.parse(JSON.stringify(data))" @on-change="handleChange"></Cascader>
            </FormItem>
            <FormItem label="详细地址" prop="entAddress">
              <i-input v-model="formItem.entAddress" placeholder="请填写企业详细地址"></i-input>
            </FormItem>
            <FormItem label="联系人姓名" prop="entLinkUser">
              <i-input v-model="formItem.entLinkUser" placeholder="请填写联系人姓名"></i-input>
            </FormItem>
            <FormItem label="用户手机" prop="entLinkPhone">
              <i-input v-model="formItem.entLinkPhone" placeholder="请填写用户手机"></i-input>
            </FormItem>
            <FormItem label="邮编">
              <i-input v-model="formItem.postCode" placeholder="请填写邮编"></i-input>
            </FormItem>
            <FormItem label="融资额度">
              <i-input v-model="formItem.finanLimit" placeholder="请填写融资额度"></i-input>
            </FormItem>
            <!-- <FormItem>
                    <Button type="success">保存</Button>
                    <Button style="margin-left: 8px">关闭</Button>
            </FormItem>-->
          </Form>
        </div>
      </Modal>
    </div>
    <LegalPerson v-show="addCompanyFlag==1" @changeShowFlag="changeShowFlag" :data="data"/>
    <UnLegalPerson v-show="addCompanyFlag==2" />
  </div>
</template>

<script>
import LegalPerson from "./legalPerson.vue";
import UnLegalPerson from "./unLegalPerson.vue";

export default {
  name: "companyInformation",
  components: {
    LegalPerson,
    UnLegalPerson
  },
  data() {
    return {
      classifyGroup: [
        {
          title: "序号",
          key: "serialNumber"
        },
        {
          title: "企业名称",
          key: "companyName"
        },
        {
          title: "统一社会信用代码",
          key: "creditCode"
        },
        {
          title: "企业法人",
          key: "legalPerson"
        },
        {
          title: "操作",
          key: "operation",
          width: 150,
          align: "center",
          render: (h, params) => {
            return h("div", [
              h("Icon", {
                props: {
                  type: "ios-create-outline",
                  size: "24"
                },
                style: {
                  color: "#00A573"
                },
                on: {
                  click: () => {
                    this.changeCompanyInfo(params.index);
                  }
                }
              })
            ]);
          }
        }
      ],
      companyInfoGroup: [],
      isShowEditInfo: false,
      formItem: {
        input: "",
        radio: "man",
        entId:"",
        creditCode:"",
        legalPerson:"",

        entAddress:"",
        selectedData:[],
        registCost:"",
        creditCode:"",
        entName:"",
        entLinkUser:"",
        entLinkPhone:"",
        postCode:"",
        finanLimit:"",
        legalRepreIden:"",
        legalReprePhone:"",
      },
      data:[],
      addressArrEnt:[],
      returnEntInfo:{},
      addCompanyFlag: 0,
      curEntId:"",
    };
  },
  mounted(){
    this.$axios('companyMsggetEntinfo',[],{userPhone:this.$token.getUUID()}).then(res=>{
      if(res.code == 200){
        this.returnEntInfo = res.data.entInfo;
        this.formItem = {
          entId:this.returnEntInfo.entId,
          radio:this.returnEntInfo.linkUserSex==0?'man':'woman',
          entName:this.returnEntInfo.entName,
          creditCode:this.returnEntInfo.creditCode,
          legalPerson:this.returnEntInfo.legalRepre,
          entAddress:this.returnEntInfo.entAddress,
          legalRepreIden:this.returnEntInfo.legalRepreIden,
          legalReprePhone:this.returnEntInfo.legalReprePhone,
          registCost:this.returnEntInfo.registCost,
          entLinkUser:this.returnEntInfo.entLinkUser,
          entLinkPhone:this.returnEntInfo.entLinkPhone,
          postCode:this.returnEntInfo.postCode,
          finanLimit:this.returnEntInfo.finanLimit
        }
        this.companyInfoGroup= [{
          serialNumber:'01',
          companyName:res.data.entInfo.entName,
          creditCode:res.data.entInfo.creditCode,
          legalPerson:res.data.entInfo.legalRepre
        }];
      }
    });
    this.$axios("searchRegionCode",[],{}).then(res=>{
      let arr0 = res.data.result[0];
      let arr1 = res.data.result[1];
      let arr2 = res.data.result[2];
      let temp = [];
      arr0.forEach(item=>{
        this.data.push({value:item.areaCode.toString(),label:item.areaName});
      });
      arr1.forEach((item,ind)=>{
        this.data.forEach((val,key)=>{
          if(item.areaCode.toString().slice(0,2) == val.value.slice(0,2)){
            val.children = val.children ? val.children : [];
            val.children.push({value:item.areaCode.toString(),label:item.areaName});
          }
        })
      });
      arr2.forEach(item=>{
        this.data.forEach(val=>{
          val.children && val.children.forEach(info=>{
            if(info.value.slice(0,4) == item.areaCode.toString().slice(0,4)){
              info.children = info.children ? info.children : [];
              info.children.push({value:item.areaCode.toString(),label:item.areaName});
            }
          })
        })
      });
    })
  },
  methods: {
    addCompanyInfo() {
      this.addCompanyFlag = 1;
      // this.addCompanyFlag = 2;
    },
    changeCompanyInfo(data) {
      console.log(data);
      this.isShowEditInfo = true;
    },
    changePage() {},
    changeShowFlag(data){
      console.log(data);
      this.addCompanyFlag = data;
    },
    emitEntInfo(data){
      let emitEntInfo = {
        entId:this.formItem.entInfo,//企业ID
        linkUserSex:this.formItem.radio=="man"?0:1,//联系人性别
        entAddress:this.formItem.entAddress,//详细地址
        proCode:this.formItem.selectedData[0].value,// 省码
        proName:this.formItem.selectedData[0].label,// 省名称
        cityCode:this.formItem.selectedData[1].value, //市码
        cityName:this.formItem.selectedData[1].label,//市名称
        countyCode:this.formItem.selectedData[2].value,//区码
        countyName:this.formItem.selectedData[2].label,// 区名
        legalRepre:this.formItem.legalPerson,// 法人名称
        legalRepreIden:this.formItem.legalRepreIden,// 法人身份证
        legalReprePhone:this.formItem.legalReprePhone,// 法人手机
        registCost:this.formItem.registCost,// 注册资本
        creditCode:this.formItem.creditCode,// 统一代码
        entName:this.formItem.entName,// 企业名称
        entLinkUser:this.formItem.entLinkUser,// 联系人姓名
        userPhone:this.formItem.entLinkPhone,// 用户手机
        postCode:this.formItem.postCode,// 邮编
        finanLimit:this.formItem.finanLimit,// 融资额度
      };
      this.$axios('companyMsgputEntinfo',[],emitEntInfo).then(res=>{
        console.log(res);
      })
    },
    handleChange(value, selectedData){
      this.selectedData = selectedData;
    }
  }
};
</script>

<style scoped>
.company-info {
  min-height: 500px;
  background: #fff;
  padding: 0 20px 20px 20px;
}
h3 {
  line-height: 50px;
  border-bottom: 1px solid #e9e9e9;
}
.addBtn {
  margin-top: 20px;
  margin-bottom: 20px;
  width: 100px;
  height: 30px;
  line-height: 30px;
  background: rgba(255, 255, 255, 1);
  border: 1px solid rgba(0, 165, 115, 1);
  border-radius: 4px;
  color: rgba(0, 165, 115, 1);
}
.edit-company-info h3 {
  line-height: 40px;
  color: rgba(0, 165, 115, 1);
  font-weight: 600;
  border-bottom: 2px solid rgba(0, 165, 115, 1);
}
.edit-company-info-content {
  margin-top: 20px;
}
</style>
<style>
/* .ivu-page-item:hover,
.ivu-page-item:active {
  border-color: rgba(0, 165, 115, 1);
} */
</style>